package com.kl.common.util;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

/**
 * 获取随机数
 * @author zjb
 * @Create Date 2014-5-21
 *
 */ 
public class RandomUtil {
	/**
	 * 随机位数常量定义：1位数
	 */
	public static final int randomNum1=1;
	/**
	 * 随机位数常量定义：6位数
	 */
	public static final int randomNum6=6;
	/**
	 * 获取相应位数随机数
	 * @param num   随机数位数
	 * @return
	 */
	public static String random(int num){
		Random random = new Random();
		String numNextStr = "";
		for(int i = 0 ; i < num ; i ++ ){
			numNextStr += random.nextInt(10);
		}
		return numNextStr;
	}

	/**
	 * 生成不重复
	 * @return
     */
	public static String notRepeatRandom(int num){
		Set<Integer> set = new HashSet<Integer>();
		Random random = new Random();
		StringBuffer stringBuffer = new StringBuffer();
		int i = num;
		while(i > 0){
			int number = random.nextInt(10);
			if(i == num && number == 0){
				number = 1;
			}
			stringBuffer.append(number);
			i--;
		}
		return stringBuffer.toString();
	}

	/**
	 * 随机六位数
	 * @return
     */
	public static int random6(){
		return (int)((Math.random()*9+1)*100000);
	}
}	
